package com.bwie.controller;

import com.bwie.pojo.TbUser;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.AdminLoginVo;
import com.bwie.vo.PageInfoVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author : Yoo19
 * @description :
 * @createDate : 2025/4/21 18:43 43
 */
@RestController
@RequestMapping("/user/index")
public class IndexController {
    @Autowired
    private TbUserService tbUserService;
    @ApiOperation("根据id获取用户")
    @PostMapping("getUserById/{id}")
    public R getUserById(@PathVariable(name = "id")Integer id){
        return tbUserService.getUserById(id);
    }

    /**
     * 管理员登陆
     * @param adminLoginVo
     * @return
     */
    @ApiOperation("用户登录")
    @PostMapping("/adminLogin")
    public R adminLogin(@RequestBody AdminLoginVo adminLoginVo){
        return tbUserService.adminLogin(adminLoginVo);
    }
    @ApiOperation("用户列表")
    @PostMapping("/getUserList")
    public R getUserList(@RequestBody PageInfoVo pageInfoVo){
        return tbUserService.getUserList(pageInfoVo);
    }

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public R Register(@RequestBody @Validated TbUser tbUser){
        return  tbUserService.register(tbUser);
    }

    @ApiOperation("审核用户")
    @PostMapping("checkUser")
    public R checkUser(@RequestBody TbUser tbUser){
        return tbUserService.checkUser(tbUser);
    }

    @ApiOperation("获取用户自己的信息")
    @PostMapping("getMyInfo")
    public R getMyInfo(){
        return tbUserService.getMyInfo();
    }

    /**
     * 修改用户的信息
     * @param tbUser
     * @return
     */
    @ApiOperation("修改用户信息")
    @PostMapping("/updateUser")
    public R updateUser(@RequestBody @Validated TbUser tbUser){
        return tbUserService.updateUser(tbUser);
    }
    @ApiOperation("上传图片")
    @PostMapping("/uploadFile")
    public R uploadFile(@RequestPart("file")MultipartFile file) {
        return tbUserService.uploadFile(file);
    }

    @ApiOperation("单个删除")
    @PostMapping("/deleteUser/{userId}")
    public R deleteUser(@PathVariable(name = "userId")Integer userId){
        return tbUserService.deleteUser(userId);
    }

    @ApiOperation("批量删除")
    @PostMapping("deleteUserBatch")
    public R deleteUserBatch(@RequestBody List<TbUser> userList){
        return tbUserService.deleteUserBatch(userList);
    }

    @ApiOperation("获取当前用户的角色")
    @PostMapping("/getMyRoleList")
    public R getMyRoleList(){
        return tbUserService.getMyRoleList();
    }

    @ApiOperation("获取当前菜单列表")
    @PostMapping("/getUserMenuTree")
    public R getUserMenuTree(){
        return tbUserService.getUserMenuTree();
    }



}
